<template>
  <div class="app-container hk-flex-column">
    <header class="hk-flex">
      <div class="hk-flex left">
        <img src="@/assets/images/tj-icon-04.png" alt />
        <div class="total-area">
          <p class="font-size16 total-title">全部项目</p>
          <span class="font-c-blue">{{ myData.count }}</span>
        </div>
      </div>
      <div class="tab-list tab-bg hk-flex sm-cg">
        <div class="icon hk-flex-column">
          <img :src="require(`@/assets/images/icon6@2x.png`)" alt />
          <p>采购方式</p>
        </div>
        <div class="hk-flex-column flex-1 cai-gou">
          <el-row :gutter="20">
            <el-col :span="8" v-for="item in myData.typeList" :key="item.procureType">
              <div class="spsm-flex">
                <span>{{ item.procureType }}</span>
                <i>{{ item.num }}</i>
              </div>
            </el-col>
          </el-row>
          <!-- <div v-for="item in myData.typeList" :key="item.procureType" class="sp-flex">
            <span>{{ item.procureType }}</span>
            <i>{{ item.num }}</i>
          </div> -->
        </div>
      </div>
    </header>
    <div class="hk-flex-column mt20 tab-content">
      <search-form
        :data="queryParams"
        :field-list="filterInfo.fieldList"
        :list-type-info="dictList"
        @handleSearch="handleQuery"
        @handleReset="resetQuery" />
      <el-row style="position: absolute; right: 20px; top: 50px">
        <el-button type="primary" size="mini" icon="el-icon-plus" @click="handleAdd">新增</el-button>
        <el-button size="small" @click="handleImport">导入</el-button>
        <el-button size="small" @click="handleExport">导出查询结果</el-button>
        <el-button size="small" @click="handleDown()">下载模板</el-button>
      </el-row>

      <hk-table
        :table-data="tableData"
        :table-columns="tableList"
        :selection="false"
        :show-index="true"
        :total="total"
        :loading="loading"
        :table-height="80"
        identifier="dealSituationList"
        operate
        expand
        :son-operate="false"
        :expand-columns="expandColumns"
        :query-params="queryParams"
        @handleSelectionChange="handleSelectionChange"
        @changePage="getDataList">
        <!-- 操作权限 -->
        <template #operate="scope">
          <el-button size="mini" type="text" @click="handleDetail(scope.row)">查看</el-button>
          <el-button size="mini" type="text" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button size="mini" type="text" @click="handleDelete(scope.row)">删除</el-button>
        </template>
        <!-- <template #operate="scope">
          <el-button size="mini" type="text" @click="handleDetail(scope.row)">查看</el-button>
          <el-button size="mini" type="text" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button size="mini" type="text" @click="handleDelete(scope.row)">删除</el-button>
        </template> -->
      </hk-table>
      <hk-upload
        ref="import_dia"
        :url="url"
        :title="title"
        :accept="accept"
        :success-desc="'文件上传成功'"
        @submit="
          getDataList()
          getSummary()
        " />
    </div>
  </div>
</template>

<script>
import { selectType, getDict, pageList, deleteItem } from '@/api/specialProject/smItem'
import SearchForm from '@/components/HkSearchform/index.vue'
import HkTable from '@/components/Hk-Table/index.vue'
export default {
  components: {
    SearchForm,
    HkTable,
  },
  beforeRouteLeave(to, from, next) {
    console.log(to, '路由')
    if (to.path === '/specialProject/smItemDetail') {
      const condition = JSON.stringify(this.queryParams)
      sessionStorage.setItem('condition', condition)
    } else {
      sessionStorage.removeItem('condition')
    }
    next()
  },
  beforeRouteEnter(to, from, next) {
    console.log(to, '路由')
    if (from.path !== '/specialProject/smItemDetail') {
      sessionStorage.removeItem('condition')
    }
    next()
  },
  data() {
    return {
      queryParams: {
        current: 1,
        size: 10,
      },
      ids: [],
      url: window.baseUrl.action + '/classified/import',
      title: '导入',
      accept: '.xlsx',
      checkedList: [],
      tableData: [],
      total: 0,
      loading: false,
      tableList: [
        { label: '项目名称', param: 'projectName', type: 'expand', showTip: true },
        { label: '采购方式', param: 'procureType' },
        { label: '招标时间', param: 'bidderTime' },
        { label: '承建单位', param: 'bidderContractorName' },
      ],
      expandColumns: [
        { label: '标包', param: 'name' },
        { label: '采购内容', param: 'procureContent' },
        { label: '采购数量', param: 'procureNum' },
        { label: '成交金额', param: 'dealMoney' },
        { label: '供应商名称', param: 'supplierName' },
        { label: '采购文件', param: 'procureFileName' },
        { label: '服务合同', param: 'giveFileName' },
        { label: '服务周期', param: 'giveDate' },
        { label: '备注', param: 'notes' },
      ],
      filterInfo: {
        fieldList: [
          { label: '关键字', type: 'input', field: 'projectName', placeholder: '请输入项目名称', maxlength: 20 },
          { label: '采购方式', type: 'select', field: 'procureType', list: 'typeList' },
        ],
      },
      dictList: {
        typeList: [],
      },
      myData: {},
    }
  },
  created() {
    var cd = sessionStorage.getItem('condition')
    if (cd) {
      var condition = JSON.parse(cd)
      this.queryParams = condition
    }
    this.getSummary()
    this.getDicts()
    this.getDataList()
  },
  methods: {
    //  查询列表
    getDataList() {
      this.loading = true
      pageList(this.queryParams).then((res) => {
        this.tableData = res.list
        this.total = res.total
        this.loading = false
        const condition = JSON.stringify(this.queryParams)
        sessionStorage.setItem('condition', condition)
      })
    },
    // 统计
    getSummary() {
      selectType().then((res) => {
        console.log(res, 'sss')
        this.myData = res
      })
    },
    // 字典值
    getDicts() {
      getDict({ code: 'procureType' }).then((res) => {
        this.dictList.typeList = res.map((o) => {
          o.label = o.dictValue
          o.value = o.dictKey
          return o
        })
      })
    },
    handleSelectionChange(obj) {
      this.ids = obj.map((i) => i.id)
      console.log(this.ids, 'sss')
    },
    //  查询
    handleQuery() {
      this.queryParams.current = 1
      this.getDataList()
    },
    //  重置
    resetQuery() {
      this.queryParams.current = 1
      this.queryParams.size = 10
      this.getDataList()
    },
    // 查看
    handleDetail(row) {
      this.$router.push({
        path: window.prefix + '/specialProject/smItemDetail',
        query: {
          id: row.id,
          title: '查看',
        },
      })
    },
    // 编辑
    handleEdit(row) {
      this.$router.push({
        path: window.prefix + '/specialProject/smItemDetail',
        query: {
          id: row.id,
          title: '修改',
        },
      })
    },
    // 新增
    handleAdd() {
      this.$router.push({
        path: window.prefix + '/specialProject/smItemDetail',
        query: {
          title: '新增',
        },
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id || this.ids.join(',')
      var that = this
      this.$modal
        .confirm('是否确认删除所选数据项？')
        .then((res) => {
          deleteItem(id).then((res) => {
            that.$modal.msgSuccess('删除成功')
            that.$nextTick(() => {
              that.handleQuery()
            })
          })
        })
        .catch((error) => {
          console.log(error)
        })
    },
    /** 导入按钮操作 */
    handleImport() {
      this.$refs.import_dia.show()
    },
    /** 下载模板操作 */
    handleDown() {
      this.gDownload(window.baseUrl.action + '/classified/exportTemplate', {}, `涉密项目模板.xlsx`)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.smDownload(
        window.baseUrl.action + '/classified/export',
        this.queryParams,
        `涉密项目${new Date().getTime()}.xlsx`
      )
    },
  },
}
</script>

<style lang="scss" scoped>
.sm-cg {
  ::-webkit-scrollbar {
    /* 对应纵向滚动条的宽度 */
    width: 6px;
    /* 对应横向滚动条的宽度 */
    height: 6px;
  }

  /* 滚动条上的滚动滑块 */
  ::-webkit-scrollbar-thumb {
    background-color: #d9d9d9;
    border-radius: 32px;
  }

  /* 滚动条轨道 */
  ::-webkit-scrollbar-track {
    background-color: #f3f5fb !important;
    border-radius: 32px;
  }
  /* 滚动条右下角小白块 */
  ::-webkit-scrollbar-corner {
    background: transparent;
  }
}
.cai-gou {
  // overflow: auto;
  padding: 0 1.25rem;
}
img {
  width: 50px;
}
.app-container {
  background: #eef0f5 !important;
  padding: 0;
  header {
    padding: 20px;
    background: #fff;
    height: 160px;
    border-radius: 4px;

    .left {
      width: 20%;
      max-width: 250px;
      img {
        width: 100px;
      }
    }
    .total-area {
      margin-left: 5px;
    }
    .tab-bg {
      background: #f3f5fb;
      padding: 22px;
      border-radius: 4px;
      width: 600px;
    }
    .icon {
      align-items: center;
      margin-right: 20px;
      p {
        margin: 0;
        margin-top: 10px;
      }
    }
    .spsm-flex {
      display: flex;
      justify-content: space-between;
      align-items: center;
      span {
        max-width: 90%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      i {
        font-style: normal;
        font-size: 18px;
        color: #333333;
        line-height: 24px;
        font-weight: 600;
      }
    }
    .tab-list {
      height: 100%;
      margin-right: 20px;
    }
  }
}
.tab-content {
  flex: 1;
  overflow: auto;
  padding: 20px;
  position: relative;
  background: #fff;
}

#app.dark-theme {
  .app-container header,
  .tab-content {
    background: transparent !important;
    color: #fff;
  }
  .tab-bg {
    background: rgba(59, 139, 255, 0.1) !important;
  }
  .spsm-flex i {
    color: #4b6eef !important;
  }
}

.total-title {
  margin-bottom: 15px;
  margin-top: 6px;
  line-height: 24px;
}
.font-size16 {
  font-size: 16px;
}
.flex-1 {
  flex: 1;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
}
.font-c-blue {
  color: #4b6eef;
  font-size: 36px;
}
.mt-20 {
  margin-top: 20px;
}
::v-deep {
  .content {
    padding-bottom: 0;
  }
}
</style>
